package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author xie
 * @since 2024-11-06
 */
@RestController
@RequestMapping("/lessons")
public class LearningLessonController {

    @Autowired
    ILearningLessonService learningLessonService;

    /**
     * 1、分页查询我的课表（Day2 - 课堂1）
     *
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> selectLearningLessonPage(PageQuery pageQuery) {
        return learningLessonService.selectLearningLessonPage(pageQuery);
    }

    /**
     * 2、查询我正在学习的课程 (Day2- 作业1)
     *
     * @return
     */
    @GetMapping("/now")
    public LearningLessonVO selectLessonsNow() {
        return learningLessonService.selectLessonsNow();
    }


    /**
     * 3、查询指定课程信息 (Day2- 作业2)
     *
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    public LearningLessonVO selectCourseId( @ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.selectCourseId(courseId);
    }



    /**
     * 4、删除指定课程信息 (Day2- 作业3)
     * @return
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除指定课程信息")
    public void DeleteCourseId(@ApiParam(value = "课程id" ,example = "1") @PathVariable Long courseId) {
        Long userId = UserContext.getUser();
        learningLessonService.deleteCourseFromLesson(userId,courseId);
    }


    /**
     * 5、统计课程学习人数 (Day2- 作业4)
     * @return
     */
    @ApiOperation("统计课程学习人数")
    @GetMapping("/{courseId}/count")
    Integer countLearningLessonByCourse(@ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.countLearningLessonByCourse(courseId);
    }



    /**
     * 6、校验当前课程是否已经报名 (Day2- 作业5)
     * @return
     */
    @GetMapping("{courseId}/valid")
    Long isLessonValid(@ApiParam(value = "课程id" ,example = "1") @PathVariable("courseId") Long courseId) {
       return learningLessonService.isLessonValid(courseId);
    }




    /**
     * 7、创建或修改学习计划
     * @return
     */
    @PostMapping("/plans")
    public void createPlans(@Valid @RequestBody LearningPlanDTO learningPlanDTO) {
         learningLessonService.createPlans(learningPlanDTO);
    }


    /**
     * 8、查询我的学习计划
     * @return
     */
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery) {
        return learningLessonService.queryMyPlans(pageQuery);
    }

}
















